﻿<Page x:Class="DvachBrowser3.Views.BoardsPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
      xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
      xmlns:controls="using:Template10.Controls"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:vm="using:DvachBrowser3.ViewModels"
      xmlns:pa="using:DvachBrowser3.Views.Partial"
      xmlns:behaviors="using:Template10.Behaviors"
      xmlns:ps="using:DvachBrowser3.PageServices"
      xmlns:localBehaviors="using:DvachBrowser3.Behaviors"
      mc:Ignorable="d" x:Name="ThisPage">

    <Page.Resources>
        <CollectionViewSource x:Name="BoardSource" IsSourceGrouped="True"></CollectionViewSource>
    </Page.Resources>
    
    <ps:PageServices.Services>
        <ps:PageServiceCollection>
            <ps:ShellAppBarPageService />
            <ps:ViewModelLifetimePageService />
        </ps:PageServiceCollection>
    </ps:PageServices.Services>
    
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="VisualStateNarrow">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="{StaticResource NarrowMinWidth}" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="VisualStateNormal">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="{StaticResource NormalMinWidth}" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <!--  header  -->
        <controls:PageHeader BackButtonVisibility="Collapsed" Frame="{x:Bind Frame, Mode=OneWay}" FontWeight="Bold"
                             Content="СПИСОК ДОСОК">
            <Interactivity:Interaction.Behaviors>
                <behaviors:EllipsisBehavior Visibility="Collapsed" />
            </Interactivity:Interaction.Behaviors>

        </controls:PageHeader>

        <Grid Grid.Row="1" Padding="4,4,4,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="100*" />
            </Grid.RowDefinitions>
            <pa:ProgressIndicatorControl Grid.Row="0" ShowMessage="True" ViewModel="{x:Bind ViewModel.Refresh.Progress, Mode=OneWay}" />
            <TextBox x:Name="SearchBox" Grid.Row="1" PlaceholderText="Поиск доски" Margin="8, 2, 8, 2" Text="{x:Bind ViewModel.Filter, Mode=OneWay}">
                <Interactivity:Interaction.Behaviors>
                    <localBehaviors:TextBoxChangeDelayBehavior>
                        <Core:CallMethodAction TargetObject="{x:Bind}" MethodName="ApplyFilter" />
                    </localBehaviors:TextBoxChangeDelayBehavior>
                </Interactivity:Interaction.Behaviors>
            </TextBox>
            <SemanticZoom Grid.Row="2">
                <SemanticZoom.ZoomedInView>
                    <GridView HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding Source={StaticResource BoardSource}}" SelectionMode="None">
                        <GridView.ItemTemplate>
                            <DataTemplate x:DataType="vm:IBoardListBoardViewModel">
                                <pa:BoardTile ViewModel="{x:Bind This}" Margin="4" Tapped="BoardTile_OnTapped">
                                    <Interactivity:Interaction.Behaviors>
                                        <localBehaviors:PopupMenuBehavior>
                                            <localBehaviors:PopupMenuBehavior.MenuFlyout>
                                                <MenuFlyout>
                                                    <MenuFlyoutItem Text="В избранное" Click="AddToFavorites_OnClick" Tag="{x:Bind This}" Visibility="{x:Bind Path=IsFavorite, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=true}" />
                                                    <MenuFlyoutItem Text="Удалить" Click="RemoveFromFavorites_OnClick" Tag="{x:Bind This}" Visibility="{x:Bind Path=IsFavorite, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=false}" />
                                                    <MenuFlyoutItem Text="Информация" Click="BoardInfo_OnClick" Tag="{x:Bind This}"/>
                                                </MenuFlyout>
                                            </localBehaviors:PopupMenuBehavior.MenuFlyout>
                                        </localBehaviors:PopupMenuBehavior>
                                    </Interactivity:Interaction.Behaviors>
                                </pa:BoardTile>
                            </DataTemplate>
                        </GridView.ItemTemplate>
                        <GridView.GroupStyle>
                            <GroupStyle>
                                <GroupStyle.HeaderTemplate>
                                    <DataTemplate>
                                        <TextBlock FontSize="{Binding ElementName=ThisPage, Path=ViewModel.StyleManager.Text.ListHeaderFontSize, Mode=OneWay}" FontWeight="SemiBold" Text="{Binding Name}" />
                                    </DataTemplate>
                                </GroupStyle.HeaderTemplate>
                            </GroupStyle>
                        </GridView.GroupStyle>
                    </GridView>
                </SemanticZoom.ZoomedInView>
                <SemanticZoom.ZoomedOutView>
                    <ListView x:Name="ZoomOutView" ItemsSource="{Binding Source={StaticResource BoardSource}, Path=CollectionGroups}">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Margin="10" FontSize="{Binding ElementName=ThisPage, Path=ViewModel.StyleManager.Text.ListHeaderFontSize, Mode=OneWay}" FontWeight="SemiBold" Text="{Binding Group.Name}" />
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </SemanticZoom.ZoomedOutView>
            </SemanticZoom>
        </Grid>
    </Grid>
</Page>

